﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Super_Star.Tools;

namespace Super_Star.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        private readonly APIDBContext db;

        public LoginController(APIDBContext context)
        {
            db = context;
        }

        //[HttpGet]
        //public Result user()
        //{
        //    Result result = new Result();
        //    var resulrData = db.EM_Enroll.ToList<EM_Enroll>();
        //    result.Data = resulrData;
        //    result.Author = "1234567@qq.com";
        //    result.Code = 200;
        //    return result;
        //}

        ///// <summary>
        ///// 登陆
        ///// </summary>
        ///// <param name="_Name">用户输入的真是姓名</param>
        ///// <param name="_Phon">用户输入的电话号码</param>
        ///// <param name="_Password">用户输入的密码</param>
        ///// <returns></returns>
        //[HttpGet("{Name}/{IsLock}/{Phon}/{Password}")]
        //public Result Login(string Name, bool IsLock, string Phon, string Password)
        //{
        //    Result result = new Result();
        //    EM_Enroll? enroll = db.EM_Enroll.Where(s => s.Name == Name && s.IsLock == IsLock && s.Phon == Phon && s.Password == Password).SingleOrDefault();
        //    result.Data = enroll;
        //    result.Author = "1234567@qq.com";
        //    result.Code = enroll == null ? 404 : 200;
        //    return result;
        //}

        //[HttpGet]

        //public IQueryable<EM_Students> StudentEntity([FromHeader] string Name, [FromHeader] string Phon, [FromHeader] string Address)
        //{
        //    IQueryable<EM_Students> query = db.EM_Students;
        //    string a = "";
        //    a += "a";
        //    if (!string.IsNullOrEmpty(Name))
        //    {
        //        query = query.Where(s => s.Name == Name);
        //    }
        //    if (!string.IsNullOrEmpty(Phon))
        //    {
        //        query = query.Where(s => s.Phon == Phon);
        //    }
        //    if (!string.IsNullOrEmpty(Address))
        //    {
        //        query = query.Where(s => s.Address == Address);
        //    }
        //    return query;
        //}





        /// <summary>
        /// 学生表用户劝退/毕业时间
        /// </summary>
        /// <param name="Id">学生用户ID</param>
        /// <returns></returns>
        [HttpDelete("{Id}/[action]")]
        public bool DelStudents(Guid Id)
        {
            EM_Students? student = new EM_Students();
            student = db.EM_Students.Where(s => s.Id == Id).FirstOrDefault();
            int result = 0;
            if (student != null)
            {
                student.DeleteTime = DateTime.Now;
                db.EM_Students.Update(student);
                result = db.SaveChanges();
            }
            return result > 0 ? true : false;
        }


        /// <summary>
        /// 教师表用户退休/辞退时间
        /// </summary>
        /// <param name="Id">教师用户ID</param>
        /// <returns></returns>
        [HttpDelete("{Id}/[action]")]
        public bool DelTeachers(Guid Id)
        {
            EM_Teachers? teacher = new EM_Teachers();
        teacher = db.EM_Teachers.Where(s => s.Id == Id).FirstOrDefault();
        int result = 0;
            if (teacher != null)
            {
                teacher.DeleteTime = DateTime.Now;
                db.EM_Teachers.Update(teacher);
                result = db.SaveChanges();
            }
            return result > 0 ? true : false;
        }
    }
}
